package com.qidian.buy.goods.config.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author: 戴着假发的程序员
 * Date: 2024-05-15 10:53
 * company: 起点编程
 **/
@Configuration
public class DirectRabbitConfig {
    // 配置直连交换机
    @Bean
    public DirectExchange directExchange(){
        // 参数1：交换机名字
        // 参数2：是否持久化
        // 参数3：是否自动删除
        return new DirectExchange("direct-exchange",true,true);
    }
    @Bean
    public Queue queueA(){
        return new Queue("direct-queue-a");
    }
    @Bean
    public Queue queueB(){
        return new Queue("direct-queue-b");
    }
    @Bean
    public Queue queueC(){
        return new Queue("direct-queue-c");
    }
    // bang绑定队列和交换机
    @Bean
    public Binding bindingQueueA(){
        // 意思：如果发送的消息中设置的路由的key是sta，就把消息发送给direct-queue-a队列
        // 参数1：队列
        // 参数2：交换机
        // 参数3：路由key
        return BindingBuilder.bind(queueA()).to(directExchange()).with("sta");
    }
    @Bean
    public Binding bindingQueueB(){
        return BindingBuilder.bind(queueB()).to(directExchange()).with("stb");
    }
    @Bean
    public Binding bindingQueueC(){
        return BindingBuilder.bind(queueC()).to(directExchange()).with("stc");
    }
}
